2 * L.Geocoder is used to make geocoding or reverse geocoding requests.
5 L
.Geocoder
= L
.Class
.extend({
7 includes
: L
.Mixin
.Events
,
10 forwardUrl
: L
.geocoderConfig
.forwardUrl
,
11 reverseUrl
: L
.geocoderConfig
.reverseUrl
,
17 initialize: function (callback
, options
) {
18 L
.Util
.setOptions(this, options
);
19 this._user_callback
= callback
;
22 geocode: function (data
) {
23 if (L
.LatLng
&& (data
instanceof L
.LatLng
)) {
24 this._reverse_geocode(data
);
25 } else if (typeof(data
) == 'string') {
26 this.options
.search
= data
;
31 _geocode: function (text
) {
33 this.options
.forwardUrl
,
37 limit
: this.options
.limit
,
38 addressdetails
: this.options
.addressdetails
,
39 "accept-language":this.options
.acceptLanguage
44 _reverse_geocode: function (latlng
) {
46 this.options
.reverseUrl
,
55 _request: function (url
, data
) {
61 jsonp
: 'json_callback',
62 success
: this._callback
,
67 _callback: function (response
,textStatus
,jqXHR
) {
68 var return_location
= {};
69 if(this.options
.search
)
70 return_location
.search
= this.options
.search
;
71 if (response
instanceof Array
&& !response
.length
) {
72 return_location
.error
= 'not found';
74 return_location
.street
= return_location
.postcode
= return_location
.postcode
=
75 return_location
.locality
= return_location
.region
= return_location
.country
= '';
77 if (response
.length
> 0)
83 var street_components
= [];
85 if (place
.address
.country
) {
86 return_location
.country
= place
.address
.country
;
88 if (place
.address
.country_code
) {
89 return_location
.country_code
= place
.address
.country_code
;
91 if (place
.address
.state
) {
92 return_location
.region
= place
.address
.state
;
96 if (place.address.county) {
97 return_location.departement = place.address.county;
100 if (place
.address
.city
) {
101 return_location
.locality
= place
.address
.city
;
102 }else if(place
.address
.county
){
103 street_components
.push(place
.address
.pedestrian
);
105 if (place
.address
.postcode
) {
106 return_location
.postcode
= place
.address
.postcode
;
108 if (place
.address
.road
) {
109 street_components
.push(place
.address
.road
);
110 }else if(place
.address
.pedestrian
){
111 street_components
.push(place
.address
.pedestrian
);
113 if (place
.address
.house_number
) {
114 street_components
.unshift(place
.address
.house_number
);
117 if (return_location
.street
=== '' && street_components
.length
> 0) {
118 return_location
.street
= street_components
.join(' ');
121 return_location
.point
= new L
.LatLng(place
.lat
, place
.lon
);
123 this._user_callback(return_location
);